package com.zy.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author hanhuafeng
 * @version V1.0
 * @description
 * @date 2023/6/2
 */
public class BeanConfig {
    /**
     * 注册OkHttp3ClientHttpRequestFactory
     *
     * @return OkHttp3ClientHttpRequestFactory
     * @date 2023/5/15 13:36
     **/
    @Bean
    public OkHttp3ClientHttpRequestFactory okHttp3ClientHttpRequestFactory() {
        return new OkHttp3ClientHttpRequestFactory();
    }

    /**
     * 注册RestTemplate
     *
     * @return RestTemplate
     * @date 2023/5/8 17:19
     **/
    @ConditionalOnMissingBean(RestTemplate.class)
    @Bean
    public RestTemplate restTemplate(OkHttp3ClientHttpRequestFactory okHttp3ClientHttpRequestFactory) {
        return new RestTemplate(okHttp3ClientHttpRequestFactory);
    }
}
